<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cookie 管理</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <style>
        body {
            font-family: 'Inter', sans-serif;
        }
        input[type="text"] {
            transition: all 0.3s ease;
        }
        button {
            transition: all 0.3s ease;
        }
        button:hover {
            transform: scale(1.05);
        }
    </style>
</head>
<body class="bg-gray-100 flex justify-center items-center h-screen">
    <div class="bg-white p-8 rounded shadow-md w-full max-w-md">
        <h1 class="text-2xl font-bold mb-4">Cookie 管理</h1>
        <input type="text" id="nameInput" placeholder="请输入姓名" class="border border-gray-300 p-2 w-full mb-4 rounded">
        <div class="flex justify-between">
            <button id="saveCookie" class="bg-blue-500 text-white p-2 rounded">保存 Cookie</button>
            <button id="loadCookie" class="bg-green-500 text-white p-2 rounded">载入 Cookie</button>
            <button id="clearCookie" class="bg-red-500 text-white p-2 rounded">清空 Cookie</button>
        </div>
    </div>
    <script>
        const nameInput = document.getElementById('nameInput');
        const saveCookieBtn = document.getElementById('saveCookie');
        const loadCookieBtn = document.getElementById('loadCookie');
        const clearCookieBtn = document.getElementById('clearCookie');

        saveCookieBtn.addEventListener('click', function() {
            const name = nameInput.value;
            if (name) {
                document.cookie = `name=${name}; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/`;
            }
        });

        loadCookieBtn.addEventListener('click', function() {
            const cookies = document.cookie.split('; ');
            for (let i = 0; i < cookies.length; i++) {
                const cookie = cookies[i].split('=');
                if (cookie[0] === 'name') {
                    nameInput.value = cookie[1];
                    break;
                }
            }
        });

        clearCookieBtn.addEventListener('click', function() {
            document.cookie = 'name=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
            nameInput.value = '';
        });
    </script>
</body>
</html>
    